package com.ylb.rent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ylb.rent.config.PageConfig;
import com.ylb.rent.entity.City;
import com.ylb.rent.util.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;

import com.ruoyi.common.enums.BusinessType;
import  com.ylb.rent.entity.Cancel;
import com.ylb.rent.service.ICancelService;


/**
 * 取消策略Controller
 * 
 * @author ylb
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/cancel/cancel")
public class CancelController
{
    @Autowired
    private ICancelService cancelService;

    /**
     * 查询取消策略列表
     */
    @PreAuthorize("@ss.hasPermi('cancel:cancel:list')")
    @GetMapping("/list")
    public String list(Cancel cancel, PageConfig pageConfig)
    {
        PageHelper.startPage(pageConfig);
        List<Cancel> list = cancelService.selectCancelList(cancel);
        return R.successJSONData(new PageInfo<>(list));

    }


    /**
     * 获取取消策略详细信息
     */
    @PreAuthorize("@ss.hasPermi('cancel:cancel:query')")
    @GetMapping(value = "/{id}")
    public String getInfo(@PathVariable("id") Long id)
    {
        return R.successJSONData(cancelService.selectCancelById(id));
    }

    /**
     * 新增取消策略
     */
    @PreAuthorize("@ss.hasPermi('cancel:cancel:add')")
    @Log(title = "取消策略", businessType = BusinessType.INSERT)
    @PostMapping
    public String add(@RequestBody Cancel cancel)
    {
        return R.successJSONData(cancelService.insertCancel(cancel));
    }

    /**
     * 修改取消策略
     */
    @PreAuthorize("@ss.hasPermi('cancel:cancel:edit')")
    @Log(title = "取消策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public String edit(@RequestBody Cancel cancel)
    {
        return R.successJSONData(cancelService.updateCancel(cancel));
    }

    /**
     * 删除取消策略
     */
    @PreAuthorize("@ss.hasPermi('cancel:cancel:remove')")
    @Log(title = "取消策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public String remove(@PathVariable Long[] ids)
    {
        return R.successJSONData(cancelService.deleteCancelByIds(ids));
    }
}
